var router = require('libs/router').router;
var pages = require('libs/pages');
var ItemMixin = require('mixins/item');
var libs = require('libs/libs');
var api = libs.api;
var List = require('modules/list/load_list')(true, 'wsStatus');

var _getLogin = SA.get('USER').login;       //获取login值
var bindEvent = function(){
    $('.hlist').find('li:first p.title').css({fontSize:'0.16rem',color:'#fa8733'})
}
var Log = React.createClass({
    mixins: [ItemMixin],
    render: function(){
        if(this.props.data){
            var waterstatus_data = this.props.data;
            var waterstatus_dataHtml = [];
            waterstatus_data.map(function(item, i){
                 waterstatus_dataHtml.push(
                     <div className="box" key={'waterstatus'+i}>
                         <p className="title">{(function(){
                                 var _d = item.description,
                                     _c = item.createBy,
                                     _p = item.phone;
                                 if (_d.indexOf('领单')>-1){
                                     return _c+''+'('+_p+')'+_d;
                                 }
                                 else {
                                     return _d
                                 }
                             })() }</p>
                         <p className="time">{item.createTime}</p>
                     </div>
                 )
            })
        }

        return(
            <div className="send-status flex flex-v">
                <div className='flex-1 f-oTouch'>
                    {(function(){
                        if (waterstatus_dataHtml.length){
                            return <List data={waterstatus_dataHtml} listClass="send-status-list"/>
                        }
                        else {
                            return (
                                <div className="uc-message-empty" id="uc-message-empty" style={{display:'block'}}>
                                    <div>暂无消息通知记录</div>
                                </div>
                            )
                        }
                    })()}

                </div>
            </div>
        )
    }
})

function start(name){
    return pages.new({
        boot: function(){
        },
        // goback: function(){
        //     router.cb = function(name){
        //         router('water/item');
        //     }
        // },
        trigger: function(self, data){
            this.libs.changeTitle('日志跟踪');
            if(data && data.back){
                var waterstatus_post = {
                    orderId: data.back,
                    login: SA.get('USER').login,
                    method: 'get'
                }
                api.req('/orderLog', waterstatus_post, function(data){
                    console.log(data);
                    self.main(self, data)
                })
            }
        },
        main: function(self, data){
            this.render(
                <Log itemDefaultMethod={bindEvent} data={data}/>,
                document.getElementById(name)
            )
            // if(!data.length){
            //     libs.msgtips('没有数据', 'center')
            //     // $("#water_status").html("<div style='text-align: center;font-size: 0.2rem;margin-top: 50px;'>没有数据！</div>");
            // }
            // else{
            //     this.render(
            //         <Log itemDefaultMethod={bindEvent} data={data}/>,
            //         document.getElementById(name)
            //     )
            // }
        },
        end: function(){
            React.unmountComponentAtNode(document.getElementById(name))
        }
    })
}
module.exports = start;
